package com.javaclimb.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javaclimb.drug.entity.Classesinfo;
import com.javaclimb.drug.entity.Imginfo;
import com.javaclimb.drug.mapper.ClassesinfoMapper;
import com.javaclimb.drug.service.IClassesinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户service实现类
 */
@Service
public class ClassesinfoServiceImpl extends ServiceImpl<ClassesinfoMapper, Classesinfo> implements IClassesinfoService {

    @Autowired
    private ClassesinfoMapper classesinfoMapper;

    @Override
    public Page<Classesinfo> selectClassesinfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Classesinfo> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(param)){
            queryWrapper.like("cname",param);
        }
        Page<Classesinfo> page = new Page<>(pageNum,pageSize);
        return classesinfoMapper.selectPage(page,queryWrapper);
    }

    @Override
    public int addClassesinfo(Classesinfo classesinfo) {
        return classesinfoMapper.insert(classesinfo);
    }

    @Override
    public int editClassesinfo(Classesinfo classesinfo) {
        return classesinfoMapper.updateById(classesinfo);
    }

    @Override
    public Classesinfo queryClassesinfoById(Integer id) {
        return classesinfoMapper.selectById(id);
    }

    @Override
    public int delClassesinfoById(Integer id) {
        return classesinfoMapper.deleteById(id);
    }

    @Override
    public List<Classesinfo> queryClassesinfoList() {
        QueryWrapper<Classesinfo> queryWrapper = new QueryWrapper<>();
        return classesinfoMapper.selectList(null);
    }
}
